﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace KaiXin001er.Trace
{
    public class Tracer
    {
        public static string fileDateStr = DateTime.Now.ToString("yyyyMMdd");
        private KT.MessageQueue.MessageQueueService mqservice = new KT.MessageQueue.MessageQueueService();
        private static Tracer tracerInstance = new Tracer();
        private Tracer()
        {
            mqservice.OnMessage += new KT.MessageQueue.MessageQueueService.DelegateOnMessage(writeToFile);
            mqservice.StartService();
        }
        public static void trace(string msg)
        {
            tracerInstance.mqservice.sendMessage(msg);
        }
        private void writeToFile(object msg)
        {
            using (StreamWriter sw = new StreamWriter("./DebugMsg" + fileDateStr + ".txt", true, Encoding.UTF8, 1024))
            {
                sw.WriteLine(msg.ToString());
                sw.Flush();
                sw.Close();
            }
        }
    }
}
